package cn.tradewin.pmp.pages.test;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.ValidationException;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

public class Validator2 {
	
	@Property
	private int age;
	
	@Property
	private String name;
	
	@Inject
	Logger log;
	
	@Log
	void onValidateFromAge() throws ValidationException {
		log.debug("age = " + age);
		if (age > 100) {
			throw new ValidationException("age must be less 100");
		}
	}
	
	@Log
	void onValidateFromInputForm() throws ValidationException {
		log.debug("ageForm ---" + age);
		log.debug("nameForm ---" + name);
		if ("refused".equals(name)) {
			throw new ValidationException("you have been refused!");
		}
		log.debug("----------after validate-----------");
	}
	
	@Log
	@OnEvent(value=EventConstants.PREPARE_FOR_SUBMIT)
	void prepareForSubmit() throws ValidationException {
		log.debug("age ---" + age);
		log.debug("name ---" + name);
	}
	
	
	@Log
	void onSuccess() {
		log.debug("age = " + age);
		log.debug("name = " + name);
	}
}
